<?php
	//Check file exist intro.mp4
	$intro = TRUE;
	if(!file_exists($this->upload_folder.''.$folder_path.'/intro.mp4')):
		$intro = FALSE;
	endif;
	
	//Disallow Play MV
	$allow =  ($this->uri->rsegment(3) == 9 && in_array($this->uri->rsegment(4),array(1,2,3,6)) ? FALSE:TRUE);	
?>
<script type="text/javascript" language="javascript">
(function($) {
/*whatever jQuery stuff*/
	$(function(){
		var is_mobile = '<?php echo $this->agent->is_mobile();?>';
		var url = "<?php echo ($intro ? image_asset_url($folder_path.'/intro.mp4'):image_asset_url($folder_path.'/mv.mp4'));?>";
		if(is_mobile){
			//Set Video Source
			$('#my_video').append("<source id='mp4' src='"+url+"' type='video/mp4'>");
			$('#my_video').attr('src',""+url+"");
			$('#my_video').attr('width',640);
			$('#my_video').attr('height',390);
			// videoplaza sdk, 4 sec time-out, callback function
			loadScript("<?php echo js_asset_url('media/html5-sdk-1.0.12.15.1-ea.min.js');?>",4000,initVideoplaza);
			// *** START - videoplaza plugin config ***
			vpConfig = {
				vphost : 'http://th-pmdplus.videoplaza.tv',
				category : 'award',
				tags : ['standard'],
				flags: [],
				playbackPosition: [] // mid-roll cue points, if any.
			}
			// *** END - videoplaza plugin config ***
			//Auto Play && Loop
			$('#my_video').attr('autoplay','autoplay');	
		} else {
			jwplayer("vdoPlayer").setup({
				autostart: true,
		      	flashplayer: "<?php echo js_asset_url('media/player.swf');?>",
		      	width: 640,
		      	height: 390,
				file: ""+url+"",
		      	plugins: "<?php echo js_asset_url('media/vp_plugin.swf');?>",
		      	vpdomain: "http://th-pmdplus.videoplaza.tv",
		      	vpshares: "award",
		      	vptags: ""
			});		
		}		
	});	
})(jQuery);

function playThis(url)
{
		var is_mobile = '<?php echo $this->agent->is_mobile();?>';
		if(is_mobile){	
			//Set Video Source
			$('#my_video').empty().append("<source id='mp4' src='"+url+"' type='video/mp4'>");
			$('#my_video').attr('src',""+url+"");
			$('#my_video').attr('width',640);
			$('#my_video').attr('height',390);		
			// videoplaza sdk, 4 sec time-out, callback function
			loadScript("<?php echo js_asset_url('media/html5-sdk-1.0.12.15.1-ea.min.js');?>",4000,initVideoplaza);
			// *** START - videoplaza plugin config ***
			vpConfig = {
				vphost : 'http://th-pmdplus.videoplaza.tv',
				category : 'award',
				tags : ['standard'],
				flags: [],
				playbackPosition: [] // mid-roll cue points, if any.
			}
			// *** END - videoplaza plugin config ***
			//Auto Play && Loop
			$('#my_video').attr('autoplay','autoplay');			
		} else {
			jwplayer("vdoPlayer").setup({
				autostart: true,
				flashplayer: "<?php echo js_asset_url('media/player.swf');?>",
			 	width: 640,
			 	height: 390,
				file: ""+url+"",
				events: {
					onComplete: function(event) {
						jwplayer().play();
					}
				},
			  	plugins: "<?php echo js_asset_url('media/vp_plugin.swf');?>",
			  	vpdomain: "http://th-pmdplus.videoplaza.tv",
			   	vpshares: "award",
			   	vptags: ""		
			});		
		}		
}

function voteCat(e,cat,at)
{
	$.ajax({
		url:web_path+'ajax_vote?t='+new Date().getTime(),
		type:'post',
		data:({
			cat:cat,
			at:at
		}),
		dataType:'json'
	}).done(function(data){	
		if(data.error == 1){
			alert('กรุณา Login ด้วย Facebook ก่อนทำการโหวต.');
			//$(document).scrollTop(0);
			$('html, body').animate({
    			scrollTop: 0
 			}, 1000);			
		} else if(data.error == 2){
			alert('คุณมีสิทธิ์ในการโหวต 1 ชั่วโมงต่อ 1 หมวดรางวัล\nคุณสามารถกลับมาโหวตในหมวดนี้อีกครั้งหลัง 1 ชั่วโมง.');
		} else if(data.error == 3){
			alert('ขออภัยค่ะ ปิดกิจกรรมการโหวตเรียบร้อยแล้ว');			
		} else {
			//change image to voted
			$(e).attr('class','buttonVoted2');
		}
	});
}
</script>
<div class="wrap_content">
	<div class="blockClear">
		<!--Left Panel-->
		<div id="leftArtist">
			<div id="artistVoteHeader"></div>
			<div id="artistLeftImage">
				<?php echo image_asset($folder_path.'/artist_left_panel.jpg','',array('width' => 185,'height' => 185));?>
			</div>
			<h2><?php echo $dataXML->left_title;?></h2>
			<h3>เพลง <?php echo $dataXML->left_song;?></h3>
			<h4>สังกัด <?php echo $dataXML->left_record;?></h4>
			<p><?php echo $dataXML->left_detail;?></p>
			<?php if($this->expireActivity < time()):?>
				<a class="buttonClosed2">ปิดโหวต</a>
			<?php else:?>
				<a href="javascript:void(0);" <?php echo ($is_vote == 0 ? 'class="buttonVote2"':'class="buttonVoted2"');?> onclick="javascript:voteCat(this,'<?php echo $this->uri->rsegment(3);?>','<?php echo $this->uri->rsegment(4);?>');"></a>			
			<?php endif;?>
		</div>
		<!--Right Panel-->
		<div id="rightArtist">
			<h2><?php echo $dataCategory[''.$this->uri->rsegment(3).''];?></h2>
			<!--Vdo Player-->
			<div id="artistVdoPlayer">
				<?php if($allow):?>
					<div id="vdoPlayer">
						<?php if($this->agent->is_mobile()):?>
							<video id='my_video' controls preload='none'></video>
						<?php endif;?>
					</div>			
				<?php endif;?>
			</div>
			<!--Social Nav-->
			<div id="socialNav">
				<div class="floatLeft">
					<div class="fb-like" data-href="<?php echo $award_url.'artist/'.$this->uri->rsegment(3).'/'.$this->uri->rsegment(4);?>" data-send="true" data-width="450" data-show-faces="false"></div>
				</div>
				<div class="floatRight">
					<a href="https://twitter.com/share" class="twitter-share-button" data-lang="th">ทวีต</a>
					<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
				</div>				
				<div class="floatRight">
<!--					<a href="javascript:void(0);" onclick="javascript:window.open('https://www.facebook.com/dialog/feed?app_id=<?php echo $this->config->item('fb_api');?>&link=<?php echo $award_url.'artist/'.$this->uri->rsegment(3).'/'.$this->uri->rsegment(4);?>&picture=<?php echo image_asset_url($folder_path.'/artist_left_panel.jpg');?>&name=<?php echo $dataCategory[''.$this->uri->rsegment(3).''];?>&redirect_uri=<?php echo $award_url;?>close_popup');" class="fb share"></a>-->
					<a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a>
					<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>					
				</div>
			</div>
			<!--Relate Vdo-->
			<div id="artistRelateVdo">
				<?php if($intro):?>
				<div class="cols first">
					<a href="javascript:void(0);" onclick="javascript:playThis('<?php echo image_asset_url($folder_path.'/intro.mp4');?>');">
						<?php echo image_asset($folder_path.'/artist_right_intro.jpg','',array('width' => 140,'height' => 90));?>
						<div class="description">
							<div class="title"><?php echo $dataXML->right_intro_title;?></div>
							<div class="subtitle"><?php echo $dataXML->right_intro_subtitle;?></div>
						</div>
					</a>
				</div>
				<?php endif;?>
				<div <?php echo ($intro ? 'class="cols"':'class="cols first"');?>>
					<?php if(!$allow):?>
						<a href="javascript:void(0);">
					<?php else:?>
						<a href="javascript:void(0);" onclick="javascript:playThis('<?php echo image_asset_url($folder_path.'/mv.mp4');?>');">
					<?php endif;?>
						<?php echo image_asset($folder_path.'/artist_right_mv.jpg','',array('width' => 140,'height' => 90));?>
						<div class="description">
							<div class="title"><?php echo $dataXML->right_mv_title;?></div>
							<div class="subtitle"><?php echo $dataXML->right_mv_subtitle;?></div>
						</div>
					</a>
				</div>
			</div>
			<center><a href="<?php echo $award_url."ment";?>"><?php echo image_asset($asset_award_image_path.'artist_ment.png','',array('width' => 640,'height' => 103));?></a></center>
			<!--Comment Facebook Plugin-->
			<div id="artistComment">
				<div class="fb-comments" data-href="<?php echo $award_url.'artist/'.$this->uri->rsegment(3).'/'.$this->uri->rsegment(4);?>" data-width="640" data-num-posts="20"></div>
			</div>
		</div>
	</div>
	<!--Sponser2-->
	<?php echo CI('module_sponser2');?>
</div>